(add-to-list 'load-path "/srv/git/sly")
(require 'sly-autoloads)
(setq inferior-lisp-program "/usr/local/bin/sbcl")
(setq sly-lisp-implementations '((sbcl ("/usr/local/bin/sbcl" "--core" "/srv/z.core" )  :coding-system utf-8-unix)))

(add-hook 'emacs-lisp-mode-hook (lambda () (lispy-mode 1)))
(add-hook 'lisp-mode-hook (lambda () (lispy-mode 1)))
;; (add-hook 'slime-repl-mode-hook (lambda () (lispy-mode 1)))
;; (add-hook 'sly-mode-hook (lambda () (lispy-mode 1)))
(add-hook 'sly-mrepl-mode-hook (lambda () (lispy-mode 1)))


(eval-after-load "sly" ; 'slime-mode 不起作用
  '(progn 
     (define-key sly-editing-mode-map (kbd "C-c C-c")
       'sly-eval-defun)
     (define-key sly-mode-map (kbd "C-x C-x")
       'sly-compile-defun)
     ))

(setq sly-mrepl-prevent-duplicate-history nil)

(require 'lispy)

;; (defun my-lispy-at ()
;;   (interactive)
;;   (lispy--space-unless "\\s-\\|\\s(\\|[:?#]\\|\\\\\\|~\\|,")
;;   (insert "@"))

(setq lispy-colon-p nil)                ; :前面不加空格
(setq lispy-no-space t
      lispy-insert-space-after-wrap nil
      ;; lispy-colon-no-space-regex
      )
(require 'le-lisp)
(setq lispy-use-sly t)
;; (eval-after-load 'lispy-mode
;;   '(progn
;;      ;; (define-key lispy-mode-map (kbd "@") 'my-lispy-at)
;;      (setq
;;       lispy-no-space t
;;       )))



(defun sly-local ()
  "sly-connect 失败会直接退出,不会运行到下面的循环"
  (interactive )
  (let ((conn (sly-connect "localhost" 5008)))
    (while (not (sly-connection-name conn))
      (sleep-for 0 100))
    (let ((repl-name (concat "*sly-mrepl for "
                             (sly-connection-name conn)
                             "*")))
      (switch-to-buffer repl-name)
      (rename-buffer (format "*本地 %s*" (sly-lisp-implementation-type))  t)
      ;; (if (and (string-match-p "slime-repl" (buffer-name (current-buffer))) (equal "slime-repl-mode" (buffer-mode)))
      ;;     (progn (message (buffer-name (current-buffer))) (rename-buffer "*本地 sbcl*" t))
      ;;   (message (buffer-name (current-buffer)))
      ;;   )
      )))

(defun sly-server ()
  "sly-server 失败会直接退出,不会运行到下面的循环"
  (interactive )
  (let ((conn (sly-connect "localhost" 5009)))
    (while (not (sly-connection-name conn))
      (sleep-for 0 100))
    (let ((repl-name (concat "*sly-mrepl for "
                             (sly-connection-name conn)
                             "*")))
      (switch-to-buffer repl-name)
      (rename-buffer (format "*远程 %s*" (sly-lisp-implementation-type))  t)
      ;; (if (and (string-match-p "slime-repl" (buffer-name (current-buffer))) (equal "slime-repl-mode" (buffer-mode)))
      ;;     (progn (message (buffer-name (current-buffer))) (rename-buffer "*本地 sbcl*" t))
      ;;   (message (buffer-name (current-buffer)))
      ;;   )
      )))

(defun sly-asdf ()
  "sly-server 失败会直接退出,不会运行到下面的循环"
  (interactive )
  (sly-eval '(asdf:load-system :app/baidu :force-not t)))


(provide 'sly-config)
